package com.itfreer.power.dao.jurisdiction;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.ConstraintMode;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.springframework.beans.BeanUtils;

import com.itfreer.form.api.JdbcBaseEntity;
import com.itfreer.power.entity.jurisdiction.DataJurisdictionItemEntity;

/**
 * 数据权限子项实体
 */
@Entity(name = "sso_jurisdiction_data_item")
@Table(indexes = { 
        @Index(name="s_j_d_i_funid", columnList="s_funId")})
public class JdbcDataJurisdictionItemEntity implements JdbcBaseEntity<DataJurisdictionItemEntity>, Serializable {

	private static final long serialVersionUID = -8484570430781818116L;

	/**
	 * 功能项ID，主键
	 */
	@Id
	@Column(name = "id", length = 50, nullable = false)
	private String itemId;
	
	/**
	 * 功能ID
	 */
	@Column(name = "s_funid", nullable = true)
	private String funId;
	
	/**
	 * 功能所属表
	 */
	@Column(name = "s_tablename", nullable = true)
	private String tableName;
	
	/**
	 * 功能所属表条件
	 */
	@Column(name = "s_tablewhere", nullable = true)
	private String tableWhere;
	
	@ManyToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
	@JoinColumn(name = "id", insertable=false, updatable=false,
		foreignKey = @ForeignKey(name = "none",value = ConstraintMode.NO_CONSTRAINT))
	private JdbcDataJurisdictionEntity dataJurisdiction;

	/**
	 * 功能ID
	 */
	public String getFunId() {
		return funId;
	}

	/**
	 * 功能ID
	 */
	public void setFunId(String funId) {
		this.funId = funId;
	}

	/**
	 * 功能项ID，主键
	 */
	public String getItemId() {
		return itemId;
	}

	/**
	 * 功能项ID，主键
	 */
	public void setItemId(String itemId) {
		this.itemId = itemId;
	}

	/**
	 * 功能所属表
	 */
	public String getTableName() {
		return tableName;
	}

	/**
	 * 功能所属表
	 */
	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

	/**
	 * 功能所属表条件
	 */
	public String getTableWhere() {
		return tableWhere;
	}

	/**
	 * 功能所属表条件
	 */
	public void setTableWhere(String tableWhere) {
		this.tableWhere = tableWhere;
	}
	
	@Override
	public void setId(String itemId) {
		setItemId(itemId);
	}

	@Override
	public void from(DataJurisdictionItemEntity t) {
		BeanUtils.copyProperties(t, this);
	}

	@Override
	public DataJurisdictionItemEntity toEntity() {
		DataJurisdictionItemEntity toEntity = new DataJurisdictionItemEntity();
		BeanUtils.copyProperties(this, toEntity);
		return toEntity;
	}
}